package cc.angis.xiugallery.provider;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import cc.angis.xiugallery.data.PostData;
import cc.angis.xiugallery.db.PostDBHelper;
import cc.angis.xiugallery.db.TableConstants;

public class PostListProvider implements ISourceProvider{
	
	private Context context;
	
	private List<PostData> postDataList;
	
	public PostListProvider(Context context){
		this.context = context;
		postDataList = new ArrayList<PostData>();
	}

	@Override
	public int getSize() {
		return postDataList.size();
	}

	@Override
	public void initSource() {
	    // Get the base URI for the People table in the Contacts content provider.
		PostDBHelper dbHelper = new PostDBHelper(context, TableConstants.TABLE_POST);
		try{
			postDataList = dbHelper.getAllPosts();
		} catch(Exception e){
			
		} finally{
			dbHelper.closeDB();
		}
	}
	
	
	public List<PostData> getPostDataList() {
		return postDataList;		
	}

	@Override
	public Object getItem(int num) {
		// TODO Auto-generated method stub
		return postDataList.get(num);
	}

	@Override
	public Object getImageItem(int num) {
		return postDataList.get(num).getImgId();
	}

	@Override
	public int getType() {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public String getItemText(int num) {
		// TODO Auto-generated method stub
		return null;
	}

}
